package edu.ynu.hhy.architectureclass.dao.daoImpl;

import edu.ynu.hhy.architectureclass.dao.CameraDataDaoCustom;
import edu.ynu.hhy.architectureclass.entity.CameraCaptureResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.web.client.RestTemplate;

@Repository
public class CameraDataDaoImpl implements CameraDataDaoCustom {

    @Value("${ys.api.capture.url}")
    private String ysCaptureUrl;

    private final RestTemplate restTemplate = new RestTemplate();

    @Override
    public String captureCameraImage(String deviceSerial, String accessToken) {
        String url = ysCaptureUrl;
        String requestBody = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&channelNo=1";
        CameraCaptureResponse response = restTemplate.postForObject(url, requestBody, CameraCaptureResponse.class);
        return response != null ? response.getPicUrl() : null;
    }
}